/*-------------------------------------
		sPlugin
	    By Scooby, 2010
-------------------------------------*/

local PLUGIN = {}

PLUGIN.Name = "NUKE!!!"
PLUGIN.Author = "Scooby"
PLUGIN.Command = "nuke"
PLUGIN.Group = 1
PLUGIN.Category = "Fun"
PLUGIN.Format = nil
PLUGIN.Use = nil
PLUGIN.Menu = {}


function PLUGIN:Main( ply, args )
	
	local rec = RecipientFilter()
	rec:AddAllPlayers()
	
	umsg.Start( "ADMIN_NUKE_ALARM", rec )
	umsg.End()
	
	timer.Simple( 6, function()
		
		umsg.Start( "ADMIN_NUKE", rec )
		umsg.End()
		
		timer.Simple( 2.5, function()
			for _,ent in ipairs( ents.GetAll() ) do
				if( ent:GetClass() == "prop_physics" ) then
					ent:GetPhysicsObject():ApplyForceCenter( Vector( 30, 1000, 90 ) * 10000 )
				end
			end
		end)
		
		timer.Simple( 4, function()
			for _,ent in ipairs( ents.GetAll() ) do
				if( ent != NULL ) then
					if( ent:GetClass() == "prop_physics" ) then
						ent:Ignite( 30, 10 )
					elseif( ent:IsPlayer() ) then
						ent:Kill()
					end
				end
			end
			timer.Simple( 6, function()
				umsg.Start( "NUKE_END", rec )
				umsg.End()
			end)
		end)
	end)
	
	spl:PrintC( spl.blue, ply:Nick(), spl.red, " Called A Nuke!!" )
	
end

if( CLIENT ) then

usermessage.Hook( "ADMIN_NUKE_ALARM", function()
	LocalPlayer():EmitSound( "admin2010/alarm.wav", 400, 100 )
end)

usermessage.Hook( "NUKE_END", function()
	hook.Remove( "HUDPaint", "NukeEffectPaint_Main" )
	local a = 255
	hook.Add( "HUDPaint", "NukeEffectPaint_END", function()
		if( a > 0 ) then
			a = a - 3
		else
			hook.Remove( "HUDPaint", "NukeEffectPaint_END" )
		end
		surface.SetDrawColor( Color( 255, 255, 255, a ) )
		surface.DrawRect( 0,0, ScrW(), ScrH() )
	end)
end)

usermessage.Hook( "ADMIN_NUKE", function()
	local a = 0
	LocalPlayer():EmitSound( "admin2010/explosion.wav", 400, 100 )
	hook.Add( "HUDPaint", "NukeEffectPaint_Main", function()
		if( a < 255 ) then
			a = a + 1
		else
			a = 255
		end
		surface.SetDrawColor( Color( 255, 255, 255, a ) )
		surface.DrawRect( 0,0, ScrW(), ScrH() )
	end)
end)

end
	
spl:AddPlugin( PLUGIN )